hysop.backend.device.opencl.opencl_tools module

Classes and tools used to handle the OpenCL backend.

  • OpenClEnvironment:

    object handling opencl platform, device … info.

  • get_opengl_shared_environment():

    build or get an OpenCL environment with openGL properties.

  • get_opencl_environment():

    build or get an OpenCL environment.

  • explore()

    explore system and display platform, devices, memory … info.

exception hysop.backend.device.opencl.opencl_tools.KernelError(err)[source]

Bases: Exception

Custom exception for kernel errors.

hysop.backend.device.opencl.opencl_tools.convert_device_type(device_type)[source]

Converts a hysop device type to corresponding opencl device type.

hysop.backend.device.opencl.opencl_tools.convert_precision(precision)[source]

Converts a hysop precision to corresponding numpy dtype.

hysop.backend.device.opencl.opencl_tools.create_queue(ctx, props=None)[source]

Returns OpenCL queue from context ctx : OpenCL context

hysop.backend.device.opencl.opencl_tools.explore()[source]

Scan system and print OpenCL environment details

hysop.backend.device.opencl.opencl_tools.get_context(devices, gl_sharing)[source]

Returns OpenCL context

Parameters:
  • devices (OpenCL device or tuple of devices) – which handles the context.

  • gl_sharing (bool) – True to build a context shared between OpenGL and OpenCL. Default=False.

Notes

Only one context is created per vendor/platform, containing all devices.

hysop.backend.device.opencl.opencl_tools.get_device(platform, device_id, device_type, strict)[source]

Returns an OpenCL device

Parameters:
  • platform (cl.Platform) – chosen platform.

  • device_id (int) – chosen device id.

  • device_type (string) – chosen device type.

  • strict (bool) – If set to true, raise an error if the device does not exist. Else fallback to the first platform device.

  • fails (Try to use given parameters and in case of)

  • context (use pyopencl)

  • function. (creation)

hysop.backend.device.opencl.opencl_tools.get_device_number(platform_id=None)[source]
hysop.backend.device.opencl.opencl_tools.get_or_create_opencl_env(mpi_params, platform_id=None, device_id=None, device_type=None, gl_sharing=False, **kargs)[source]

Create or an OpenClEnvironment from given parameters if it does not already exists. All environements are kept alive (cached) in a dictionary local to this function (ie. all opencl operators can share the same OpenClEnvironment).

hysop.backend.device.opencl.opencl_tools.get_platform(platform_id, strict)[source]

Returns an OpenCL platform platform_id : int

OpenCL platform ID.

strict: bool

If set to true, raise an error if the platform does not exist. Else fallback to the default platform.

hysop.backend.device.opencl.opencl_tools.get_work_items(resolution, vector_width=1)[source]

Set the optimal work-item number and OpenCL space index.

Parameters:
  • resolution (tuple) – local mesh resolution

  • vector_width (int) – OpenCL vector types width

Returns:

  • int (work-item number)

  • tuple (global space index)

  • tuple (local space index)

  • Use 64 work-items in 3D and 256 in 2D.

  • Use Both the number from device capability

  • The problem must be a multiple of and greater

  • than work-item number * vector_width

hysop.backend.device.opencl.opencl_tools.parse_opencl_file(f, n=8, nb_remesh_components=1)[source]

Parse a file containing OpenCL sources.

Parameters:
  • f (string) – file name

  • n (int, optional) – vector width, default=8

  • nb_remesh_components (int) – number of remeshed components

Return type:

string, the parsed sources.

Notes

  • __N__ is expanded as an integer corresponding to vector width.

  • __NN__ instruction is duplicated to operate on each vector component:

    • if line ends with ‘;’, the whole instruciton is duplicated.

    • if line ends with ‘,’ and contains ‘(float__N__)(’, the float element is duplicated

  • Remeshing fields components are expanded as follows : All code between ‘__RCOMPONENT_S__’ and ‘__RCOMPONENT_E__’ flags are duplicated n times with n the number of components to compute. In this duplicated code, the flag ‘__ID__’ is replaced by index of a range of lenght the number of components. A flag ‘__RCOMPONENT_S__P__’ may be used and the duplicated elements are separated with ‘,’ (for function parameters expanding).

Examples with a 4-width vector code:

float__N__ x;           ->  float4 x;

x.s__NN__ = 1.0f;       ->  x.s0 = 1.0f;
                            x.s1 = 1.0f;
                            x.s2 = 1.0f;
                            x.s3 = 1.0f;

x = (int__N__)(__NN__,  ->  x = (int4)(0,
                );                      1,
                                        2,
                                        3,
                                        );

Examples with a 2 components expansion code:

__RCOMP_P __global const float* var__ID__,
-> __global const float* var0,__global const float* var1,

__RCOMP_I var__ID__[i] = 0.0;
-> var0[i] = 0.0;var1[i] = 0.0;

aFunction(__RCOMP_P var__ID__, __RCOMP_P other__ID__);
-> aFunction(var0, var1, other0, other1);